#include <cstdio>
#include <queue>

const int N = 1e3 + 5;
int n, m, a, b, c, d;
int sum[N][N], minn[N][N], minn2[N][N];

inline int A(int i, int j) {
  return sum[i][j] - sum[i][j - d] - sum[i - c][j] + sum[i - c][j - d];
}

inline int B(int i, int j) {
  return sum[i][j] - sum[i][j - b] - sum[i - a][j] + sum[i - a][j - b];
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P2219 [HAOI2007]修筑绿化带.in", "r", stdin);
  freopen("P2219 [HAOI2007]修筑绿化带.out", "w", stdout);
#endif
#endif

  scanf("%d%d%d%d%d%d", &n, &m, &a, &b, &c, &d);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      scanf("%d", &sum[i][j]);
      sum[i][j] += sum[i][j - 1];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) { sum[i][j] += sum[i - 1][j]; }
  }
  std::deque<int> q;
  for (int i = c + 1; i < n; ++i) {
    while (!q.empty()) q.pop_back();
    for (int j = d + 1; j < m; ++j) {
      while (!q.empty() && q.front() < j - b + 2 + d) q.pop_front();
      while (!q.empty() && A(i, q.back()) > A(i, j)) q.pop_back();
      q.push_back(j);
      minn[i][j + 1] = A(i, q.front());
    }
  }
  for (int j = b; j <= m; ++j) {
    while (!q.empty()) q.pop_back();
    for (int i = c + 1; i < n; ++i) {
      while (!q.empty() && q.front() < i - a + 2 + c) q.pop_front();
      while (!q.empty() && minn[q.back()][j] > minn[i][j]) q.pop_back();
      q.push_back(i);
      minn2[i + 1][j] = minn[q.front()][j];
    }
  }
  int ans = 0;
  for (int i = a; i <= n; ++i) {
    for (int j = b; j <= m; ++j) { ans = std::max(ans, B(i, j) - minn2[i][j]); }
  }
  printf("%d", ans);
  return 0;
}